package org.liziing.shortlink.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.liziing.shortlink.admin.common.convention.result.Result;
import org.liziing.shortlink.admin.common.convention.result.Results;
import org.liziing.shortlink.admin.remote.ShortLinkServiceActualRemoteService;
import org.liziing.shortlink.admin.remote.dto.req.RecycleBinPageReqDTO;
import org.liziing.shortlink.admin.remote.dto.req.RecycleBinRecoverReqDTO;
import org.liziing.shortlink.admin.remote.dto.req.RecycleBinRemoveReqDTO;
import org.liziing.shortlink.admin.remote.dto.req.RecycleBinSaveReqDTO;
import org.liziing.shortlink.admin.remote.dto.resp.ShortLinkPageRespDTO;
import org.liziing.shortlink.admin.service.RecycleBinService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 回收站管理控制层
 */
@RestController
@RequiredArgsConstructor
public class RecycleBinController {

    private final ShortLinkServiceActualRemoteService shortLinkServiceActualRemoteService;
    private final RecycleBinService recycleBinService;
    /**
     * 移至回收站
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/save")
    public Result<Void> saveRecycleBin(@RequestBody RecycleBinSaveReqDTO requestParam) {
        shortLinkServiceActualRemoteService.saveRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 分页查询回收站短链接
     * @param requestParam 分页查询 请求参数
     * @return 分页查询 返回参数
     */
    @GetMapping("/api/short-link/admin/v1/recycle-bin/page")
    public Result<Page<ShortLinkPageRespDTO>> pageRecycleBin(RecycleBinPageReqDTO requestParam) {
        return recycleBinService.pageRecycleBin(requestParam);
    }

    /**
     * 恢复短链接功能
     * @param requestParam 请求参数
     * @return 响应参数
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/recover")
    public Result<Void> recoverShortLink(@RequestBody RecycleBinRecoverReqDTO requestParam) {
        shortLinkServiceActualRemoteService.recoverShortLink(requestParam);
        return Results.success();
    }

    /**
     * 删除回收站短链接功能
     * @param requestParam
     * @return
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/remove")
    public Result<Void> removeRecycleBin(@RequestBody RecycleBinRemoveReqDTO requestParam) {
        shortLinkServiceActualRemoteService.removeRecycleBin(requestParam);
        return Results.success();
    }
}
